package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.Order
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IOrderListView
import de.baumann.browser.model.OrderModel

class HashOrderPresenter : OdinPayPresenter<IOrderListView>() {
    private val orderModel = OrderModel()

    fun cancelOrder(tradeNo: String) {
        this.orderModel.cancelOrder(tradeNo)
                .subscribe(object : OdinObserver<Any>() {
                    override fun onSuccess(data: Any?) {
                        if (view != null)
                            view.orderCancelled()
                    }
                })
    }

    fun getUnpaidHashOrder() {
        this.orderModel.getOrders(2, 1, view.pageNum)
                .subscribe(object : OdinObserver<List<Order>>(view) {
                    override fun onSuccess(data: List<Order>?) {
                        if (view != null) {
                            view.setOrders(data)
                        }
                    }
                })
    }


    fun getPaidHashOrder() {
        if (view==null){
            return
        }

        this.orderModel.getOrders(2, 2, view.pageNum)
                .subscribe(object : OdinObserver<List<Order>>() {
                    override fun onSuccess(data: List<Order>?) {
                        if (view != null) {
                            view.setOrders(data)
                        }
                    }
                })
    }
}